package com.uni.domain;

import java.util.Collection;
import java.util.HashSet;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.UserDetails;

public class UserDetailsImpl extends Identifier implements UserDetails {
	
	private static final long serialVersionUID = 2422881708922038732L;

	private String name;
	private String password;
	private Collection<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
	private boolean enabled;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		System.out.println("SET NAME = " + name);
		this.name = name;
	}

	public void setPassword(String password) {
		System.out.println("SET PASSWORD = " + password);
		this.password = password;
	}

	public void setEnabled(Boolean enabled) {
		System.out.println("SET ENABLED = " + enabled);
		this.enabled = enabled;
	}
	
	public void setPrepod(Boolean val){
		System.out.println("SET PREPOD = " + val);
		if(val){
			authorities.add(new GrantedAuthorityImpl("ROLE_PREPOD"));
		}
	}
	
	public void setStudent(Boolean val){
		System.out.println("SET STUDENT = " + val);
		if(val){
			authorities.add(new GrantedAuthorityImpl("ROLE_STUDENT"));
		}
	}

	public void setAdmin(Boolean val){
		System.out.println("SET ADMIN = " + val);
		if(val){
			authorities.add(new GrantedAuthorityImpl("ROLE_ADMIN"));
		}
	}
	
	
	//****************************

	public boolean getEnabled() {
		return enabled;
	}
	
	public boolean getPrepod(){
		return false;
	}
	
	public boolean getStudent(){
		return false;
	}

	public boolean getAdmin(){
		return false;
	}
	
	//********************************
	
	@Override
	public Collection<GrantedAuthority> getAuthorities() {
		return authorities;
	}

	@Override
	public String getPassword() {
		return password;
	}

	@Override
	public String getUsername() {
		return name;
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return enabled;
		
	}

}
